package com.lanou.tk.tourism.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.lanou.tk.tourism.R;
import com.lanou.tk.tourism.entity.HotelDetailsData;
import com.lanou.tk.tourism.tool.GetBitmaps;

import java.util.List;


/**
 * Created by dllo on 15/10/30.
 */
public class HotelDetailsAdapter extends RecyclerView.Adapter<HotelDetailsAdapter.LatestViewHolder>{

private List<HotelDetailsData> hotelDetailsDatas;
    private RequestQueue queue;

    public HotelDetailsAdapter(Context c) {
        queue = Volley.newRequestQueue(c);
    }


    public void addDatas(List<HotelDetailsData> datas) {
        hotelDetailsDatas = datas;
        notifyDataSetChanged();
    }

    public class LatestViewHolder extends RecyclerView.ViewHolder {
        private ImageView details_hotel_photo;
        private TextView details_hotel_cnname;
        private TextView details_hotel_enname;
        private TextView details_hotel_ranking;
        private TextView details_hotel_star;
        private TextView details_hotel_price;



        public LatestViewHolder(View itemView) {
            super(itemView);

            details_hotel_photo = (ImageView) itemView.findViewById(R.id.details_hotel_photo);
            details_hotel_cnname = (TextView) itemView.findViewById(R.id.details_hotel_cnname);
            details_hotel_enname = (TextView) itemView.findViewById(R.id.details_hotel_enname);
            details_hotel_ranking = (TextView) itemView.findViewById(R.id.details_hotel_ranking);
            details_hotel_star = (TextView) itemView.findViewById(R.id.details_hotel_star);
            details_hotel_price = (TextView) itemView.findViewById(R.id.details_hotel_price);


        }
    }


    @Override
    public int getItemCount() {
        return hotelDetailsDatas != null && hotelDetailsDatas.size() > 0 ? hotelDetailsDatas.size() : 0;
    }


    @Override
    public void onBindViewHolder(LatestViewHolder holder, int position) {
           if(hotelDetailsDatas != null && hotelDetailsDatas.size() > 0){
               HotelDetailsData hotelDetailsData = hotelDetailsDatas.get(position);
               holder.details_hotel_cnname.setText(hotelDetailsData.getCnname());
               holder.details_hotel_enname.setText(hotelDetailsData.getEnname());
               holder.details_hotel_star.setText(hotelDetailsData.getStar());
               Log.d("lanou", hotelDetailsData.getEnname());

               holder.details_hotel_ranking.setText(hotelDetailsData.getRanking() + "");

               String imgUrl = hotelDetailsData.getPhoto();

               GetBitmaps.getBitmapRequest(imgUrl, holder.details_hotel_photo);

           }

    }





    @Override
    public LatestViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {

        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());

        View v = inflater.inflate(R.layout.adapter_details_hotel, null);

        return new LatestViewHolder(v);
    }
}
